| Total Complexity | 5 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | export class ArrayUtils { |
||
| 2 | public static range(start: number, end: number, step: number = 1) { |
||
| 3 | function* generateRange() { |
||
| 4 | let x = start - step; |
||
| 5 | while (x <= end - step) { |
||
| 6 | yield (x += step); |
||
| 7 | } |
||
| 8 | } |
||
| 9 | |||
| 10 | return { |
||
| 11 | [Symbol.iterator]: generateRange |
||
| 12 | }; |
||
| 13 | } |
||
| 14 | |||
| 15 | public static flatMap<T, V>(items: T[], fn: (x: T) => V[]): V[] { |
||
| 16 | const arr = []; |
||
| 17 | for (let item of items) { |
||
| 18 | arr.push(...fn(item)); |
||
| 19 | } |
||
| 20 | return arr; |
||
| 21 | } |
||
| 23 |